package com.ambow.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.ambow.dao.AdminDao;
import com.ambow.model.Admin;
import com.ambow.utils.BaseDAO;

public class AdminDaoImpl implements AdminDao{

	//查询单条数据
	//查询单条数据
	@Override
	public Admin adminLogin(String account, String pwd) {
		
		String param[] = {account,pwd};
//		hibernate   HQL语句
		String sql = "from Admin where account=? and pwd = ?";
		Admin admin = (Admin) BaseDAO.queryOne(sql, param);
		return admin;
		
	}

	//分页查询数据
	@Override
	public List<Admin> listByPage(int page) {
		List<Admin> list = new ArrayList<Admin>();
		String sql = "from Admin  order by createDate";
		
		list = BaseDAO.queryByPage(sql, null, page, 20);
		
		return list;
		
	}
	
	//查询多条数据
	@Override
	public List<Admin> list(String name) {
		List<Admin> list = new ArrayList<Admin>();
		String sql = "from Admin where name like ?";
		String param[] = {name};
		list = BaseDAO.query(sql,param);
		
		return list;
		
	}

	//修改数据
	@Override
	public boolean update(Admin admin) {
		boolean result = BaseDAO.update(admin);
		return result;
	}

	
	//删除数据
	@Override
	public boolean delete(Admin admin) {
		boolean result = BaseDAO.delete(admin);
		return result;
	}
	
	//增加数据
	public boolean add(Admin admin) {
		boolean result = BaseDAO.add(admin);
		return result;
	}
	
	
	public static void main(String[] args) {
		
		Admin admin = new Admin();
		admin.setId(1);
		admin.setAccount("lisi");
		AdminDao dao = new AdminDaoImpl();
		dao.list("admin");
		
		
	}
	


}
